//
//  NewDeventCell.m
//  InformationFoot
//
//  Created by 魔曦 on 2018/7/12.
//  Copyright © 2018年 MacBook. All rights reserved.
//

#import "NewDeventCell.h"

@implementation NewDeventCell

- (void)setEventModel:(MXDEventModel *)eventModel{
    _eventModel = eventModel;
    
    if (eventModel.matchStatus == 2 ||
        eventModel.matchStatus == 3 ||
        eventModel.matchStatus == 4 ||
        eventModel.matchStatus == 5 ||
        eventModel.matchStatus == 6 ||
        eventModel.matchStatus == 7 ) {
        
        int matchStartTime = [[MXLJUtil getNowDateTimeString] doubleValue] - [eventModel.startBallTime doubleValue] ;
        
        NSString * startTime = @"" ;
        if (matchStartTime/3600) {
            startTime = [NSString stringWithFormat:@"%d:%02d:%02d",matchStartTime/3600,matchStartTime%3600/60,matchStartTime%60] ;
        } else if (matchStartTime/60) {
            startTime = [NSString stringWithFormat:@"%d:%02d",matchStartTime/60,matchStartTime%60] ;
        } else {
            startTime = [NSString stringWithFormat:@"%d",matchStartTime] ;
            
        }
        
        NSMutableParagraphStyle * paragraph = [[NSMutableParagraphStyle alloc]init] ;
        paragraph.alignment = NSTextAlignmentCenter ;
        NSMutableAttributedString *
        matchTimeAttributedString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ %@",eventModel.eventShortName,startTime]] ;
        [matchTimeAttributedString addAttributes:@{NSFontAttributeName : fontSize(scaleWithSize(12)),NSForegroundColorAttributeName:mx_redColor,NSParagraphStyleAttributeName:paragraph} range:NSMakeRange(eventModel.eventShortName.length + 1, startTime.length)];
        
        self.timeLabel.attributedText = matchTimeAttributedString ;
        
        self.stateLabel.text = @"比赛正在进行" ;
        self.stateLabelHeight.constant = 12;

        self.stateLabel.textColor = mx_BlueColor ;
//        self.timeLabel.text = @"" ;
        self.notGameLabel.text = @"-";

        self.firstNumLabel.text = [NSString stringWithFormat:@"%ld",eventModel.homeTeamScore ] ;
        self.secondNumLabel.text = [NSString stringWithFormat:@"%ld",eventModel.visitTeamScore] ;


        
    } else {
        if(eventModel.matchStatus == 1){
            self.stateLabel.text = @"" ;
            self.stateLabelHeight.constant = 5;
            self.notGameLabel.text = @"比赛即将开始";
        }
        
        self.firstNumLabel.text = @"";
        self.secondNumLabel.text = @"";
        
        self.stateLabel.textColor = mx_FontLightGreyColor ;
        
//        self.timeLabel.text = [NSString stringWithFormat:@"%@",eventModel.eventShortName] ;
        self.timeLabel.text = [self timeInterverlToDateStr:eventModel.startGameTime] ;
        
    }
    
    self.firstNameLabel.text = eventModel.homeTeamName ;
    
    self.secondNameLabel.text = eventModel.visitTeamName ;
    
    self.leagueLabel.text = eventModel.eventShortName;
    
    if (eventModel.isCollect == 1) {
        [self.attentionBtn setTitle:@"已关注" forState:UIControlStateNormal];

    } else {
        [self.attentionBtn setTitle:@"+关注" forState:UIControlStateNormal];

        [self.attentionBtn setTintColor:[UIColor cyanColor]];
    }
    
//    if (eventModel.matchStatus == 2 ||
//        eventModel.matchStatus == 3 ||
//        eventModel.matchStatus == 4 ||
//        eventModel.matchStatus == 5 ||
//        eventModel.matchStatus == 6 ||
//        eventModel.matchStatus == 7 ||
//        eventModel.matchStatus == 8) {
//        self.homeScore.hidden = NO ;
//        self.awayScore.hidden = NO ;
//        self.blackView.hidden = NO ;
//    } else {
//        self.homeScore.hidden = YES ;
//        self.awayScore.hidden = YES ;
//        self.blackView.hidden = YES ;
//    }
    
    if (eventModel.matchStatus == 8) {
        self.firstNumLabel.textColor = [UIColor blackColor] ;
        self.firstNumLabel.text = [NSString stringWithFormat:@"%ld",eventModel.homeTeamScore ] ;

        self.secondNumLabel.text = [NSString stringWithFormat:@"%ld",eventModel.visitTeamScore] ;

        self.secondNumLabel.textColor = [UIColor blackColor] ;
        self.stateLabel.text = @"比赛已经结束" ;
        self.timeLabel.text = [NSString stringWithFormat:@"%@ %@",eventModel.eventShortName ,[self timeInterverlToDateStr:eventModel.startGameTime]] ;
    } else {
        self.firstNumLabel.textColor = mx_redColor ;
        self.secondNumLabel.textColor = mx_BlueColor ;
    }
}
- (NSString *)timeInterverlToDateStr:(NSString *)timeStr {
    //timeStr时间戳
    NSTimeInterval time=[timeStr doubleValue];//因为时差问题要加8小时 == 28800 sec
    
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    
    //    NSLog(@"date:%@",[detaildate description]);
    
    //实例化一个NSDateFormatter对象
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    //设定时间格式,这里可以设置成自己需要的格式yyyy.MM.dd HH:mm
    [dateFormatter setDateFormat:@"MM-dd HH:mm"];
    
    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
    
    return currentDateStr;
}


- (IBAction)attentionBtn:(UIButton *)sender {
    if (self.eventCellAttentBlock != nil) {
        
        self.eventCellAttentBlock() ;
        
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    _leagueLabel.font = fontSize(scaleWithSize(10.0f));
    _firstNameLabel.font = fontSize(scaleWithSize(16.0f));
    _secondNameLabel.font = fontSize(scaleWithSize(16.0f));
    _timeLabel.font = fontSize(scaleWithSize(10.0f));
    _firstNumLabel.font = fontSize(scaleWithSize(15.0f));

    _secondNumLabel.font = fontSize(scaleWithSize(15.0f));
    _notGameLabel.font = fontSize(scaleWithSize(15.0f));


}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
